package Class;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;

// 取款界面
public class WithdrawalJFrame extends JFrame implements ActionListener {
    JLabel labelMoney = new JLabel("取出钱数");
    JTextField tfdMoney = new JTextField(12);
    JButton btnConfirm = new JButton("确定");
    JButton btnClear = new JButton("清空");

    public WithdrawalJFrame() {
        this.setName("村镇银行业务储蓄系统");
        this.setTitle("取款界面");
        this.setSize(300, 200);
        this.setAlwaysOnTop(true);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(2);
        this.setLayout(new FlowLayout());
        this.setVisible(true);

        JPanel p1 = new JPanel();
        p1.add(labelMoney);
        p1.add(tfdMoney);
        JPanel p2 = new JPanel();
        p2.add(btnConfirm);
        p2.add(btnClear);
        this.add(p1);
        this.add(p2);
        btnConfirm.addActionListener(this);
        btnClear.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == btnConfirm) {
            try {
//                int op = QueryMoney();
//                if(op == 1) {
//                    WithdrawalSuccessJFrame successJFrame = new WithdrawalSuccessJFrame();
//                }
//                if(op == 2) {
//
//                }
//                if(op == 3) {
//                    WithdrawalFailedJFrame failedJFrame = new WithdrawalFailedJFrame();
//                }
            } catch (Exception exception) {
            }
        }
        if (e.getSource() == btnClear) {
            tfdMoney.setText("");
        }
    }

    public void getDemandInterest() throws Exception {
        double money = Double.parseDouble(tfdMoney.getText());

    }
    public void QueryMoney() throws Exception {
//        BalanceQueryJFrame balanceQueryJFrame = new BalanceQueryJFrame();
//        balanceQueryJFrame.setVisible(false);
//        double demandMoney = balanceQueryJFrame.queryDemandBalance(LoginJFrame.getUser());
////          System.out.println(demandMoney);
//        double TimeMoney = balanceQueryJFrame.queryTimeBalance(LoginJFrame.getUser());
////          System.out.println(TimeMoney);
//        double needMoney = Double.parseDouble(tfdMoney.getText());
////          System.out.println(needMoney);
//
//        if(demandMoney >= needMoney) {
//            return 1;
//        }
//        else if(TimeMoney >= needMoney) {
//            return 2;
//        }
//        else {
//            return 3;
//        }
    }
}
